package com.buptlogistics.creditinvestigation.fragment;


import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.buptlogistics.creditinvestigation.R;
import com.buptlogistics.creditinvestigation.activity.CommonActivity;
import com.buptlogistics.creditinvestigation.app.AppData;
import com.buptlogistics.creditinvestigation.app.BaseFragment;


/**
 * A simple {@link Fragment} subclass.
 */
public class LoanConfirmAgreementHousingFragment extends BaseFragment {


    private View view;
    private Button btn_accept;
    private TextView tv_content;


    private String company;

    private String applyEntity;


    public LoanConfirmAgreementHousingFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_loan_confirm_agreement_housing, container, false);
        AppData.getInstance(LoanConfirmAgreementHousingFragment.this.getActivity());
        //initData();
        initViews();
        initEvents();
        return view;
    }

    //private void initData() {
    //    Bundle data = getArguments();
    //    company = AppData.getInstance(LoanConfirmAgreementHousingFragment.this.getActivity()).getUserCompany();
    //    applyEntity = data.getString("applyEntity");
    //}

    protected void initViews() {
        btn_accept = (Button) findViewById(R.id.btn_loan_confirm_agreement_housing_accept);
        tv_content = (TextView) findViewById(R.id.tv_loan_detail_agreement_housing_content);
        String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" +
                "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                "<head>\n" +
                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" +
                "<title>仓储合作协议</title>\n" +
                "</head>\n" +
                "\n" +
                "<body>\n" +
                "<p>甲方（质权人）：<strong>xx银行</strong></p>\n" +
                "<p>地址：<strong>海淀区XX路xx号</strong></p>\n" +
                "<p>乙方（质押人）：<strong>" + "company" + "</strong></p>\n" +
                "<p>地址：<strong>广东省xx区xx路</strong></p>\n" +
                "<p>丙方（仓储单位）：<strong>上海郑明物流有限公司</strong></p>\n" +
                "<p>地址：<strong>北京市xx区xx路</strong></p>\n" +
                "<p>为了支持乙方的生产、经营，全面建立和发展现代新型银企合作关系，甲、乙、丙三方本着优势互补，平等互利的原则，经充分协商，共同达成本协议，并自愿全面遵守执行。</p>\n" +
                "<blockquote>\n" +
                "  <p>第一条   甲、乙、丙三方的合作内容为：</p>\n" +
                "</blockquote>\n" +
                "<p>就乙方存入丙方仓库内的货物，丙方按本协议的约定向乙方出具仓单，乙方需要资金时，乙方可按本合同约定申请甲方给予银行贷款服务，并以前述仓单作为甲方实现债权的质押担保。</p>\n" +
                "<blockquote>\n" +
                "  <p>第二条   第一条所述合作内容的具体的操作程序及各方的相关权利、义务为：</p>\n" +
                "</blockquote>\n" +
                "<p>一、 货物的存入</p>\n" +
                "<p>1、乙方根据生产经营的需要，将货物存入丙方，请丙方开具仓单，作为提货或用于为银行债权设定质押担保的权利凭证。</p>\n" +
                "<p>二、贷款的期限</p>\n" +
                "<p>1、每笔贷款的期限最长不得超过6个月（含）。</p>\n" +
                "<p>2、每笔贷款到期前5个银行工作日，乙方应当足额将贷款款项提前归还给甲方。</p>\n" +
                "<p>六、核押</p>\n" +
                "<p>1、甲方与乙方订立质押合同后，出质的仓单由甲方保管，同时向丙方办理核押手续，将仓单已出质的情况通知丙方。</p>\n" +
                "<p>本协议履行过程中，如发生争议，各方应当协商解决，如协商不成，任何一方可以向甲方所在地人民法院提起诉讼。</p>\n" +
                "               \n" +
                "</body>\n" +
                "</html>\n";

        tv_content.setMovementMethod(ScrollingMovementMethod.getInstance());//滚动
        tv_content.setText(Html.fromHtml(html));
    }

    protected void initEvents() {
        btn_accept.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle data = new Bundle();
                data.putInt("fragmentType", 9);
                // 创建一个Intent
                Intent intent = new Intent(LoanConfirmAgreementHousingFragment.this.getActivity(),
                        CommonActivity.class);
                intent.putExtras(data);
                // 启动intent对应的Activity
                startActivity(intent);
            }
        });
    }

    protected View findViewById(int id) {
        return view.findViewById(id);
    }


}
